home *** CD-ROM | disk | FTP | other *** search
- Path: news.lpr.carel.fi!usenet
- From: Ari Lukumies <aril@cmt.lpr.mail.carel.fi>
- Newsgroups: comp.lang.c
- Subject: Re: Help with pointer alignment
- Date: Thu, 08 Feb 1996 14:58:31 +0200
- Organization: Carelcomp Forest
- Message-ID: <3119F377.369F@cmt.lpr.mail.carel.fi>
- References: <4fb0op$8l8@hermes.louisville.edu>
- NNTP-Posting-Host: renoir.cclahti.carel.fi
- Mime-Version: 1.0
- Content-Type: text/plain; charset=us-ascii
- Content-Transfer-Encoding: 7bit
- X-Mailer: Mozilla 2.0b6a (WinNT; I)
-
- Alan Wild wrote:
- >
- > I am having a small problem with pointer alignment in a library I am
- > developing. lint reports:
- >
- > "queue.c", line 13: warning: possible pointer alignment problem, op CAST
- >
- > And the code is as follows:
- >
- > struct dataChain {
- > ORD64 dataf;
- > ORD64 be;
- > int cycle;
- > struct dataChain *next;
- > };
- >
- > typedef struct dataChain queueentry;
- >
- > void Append ( queueentry new, queue *Q ) {
- >
- > queueentry *temp = (queueentry *)malloc( sizeof( queueentry ) );
- >
- > temp->dataf = new.dataf;
- > temp->be= new.be;
- > temp->cycle = new.cycle;
- > temp->next = new.next;
- >
- > AppendData ( temp, Q );
- > }
- >
- > The line in error is the malloc statement. What have I done
- > wrong/dangerously? I would like to correct this if at all possible.
- > This is the only pententially problematic warning in my code and I would
- > like to avoid any problems. :)
- >
- > Note: I have checked through several books and the C FAQ, but I haven't
- > seen anything. My co-workers also did not have a clue about this one.
- >
- > I am developing on anIBM rs6000 running AIX 3.2.5. I am using the
- > native version of lint.
- >
-
- If the compiler uses 8-byte alignment and sizeof(int) is 32 bits, there may be 4 bytes
- padding in between 'cycle' and 'next' in the structure. This is perhaps the reason of the
- warning. (I take it ORD64 means a 64-bit variable type.) In this case, it should not
- matter, but if the 'Append' function is to be called outside of this compilation module
- (eg. it may reside in a library), and the calling module has been compiled with different
- padding, this will lead to problems, since 'next' will not get properly initialized inside
- Append since the actual byte offset inside 'new' will be different.
-
- Later,
- AriL
- --
- All my opinions are mine and mine alone.
-